<template>
	<view class="box" :style="{'min-height':minHeight}">
		<view v-if="recordList.length" >
			<view 
				v-for="item in recordList" 
				class="item" 
				:key="item.id"	
			>
				<view class="item-title">
					<view class="item-title-time">{{item.create_time}}</view>
					<view>
						<u-tag 
							size='mini'
							mode='dark' 
							:text="item.is_pass == 0 ? '不合格' : '合格'" 
							:type="item.is_pass == 1 ? 'success' : 'error'" 
						/>
					</view>
				</view>
				<view class="long-time">答题时长：{{item.exam_time}}</view>
				<view class="item-card">
					<view class="item-card-item">
						<view class="item-card-item-num">
							{{item.yes_num}}题
						</view>
						<view class="item-card-item-intro">
							答对	
						</view>
					</view>
					<view class="item-card-item">
						<view class="item-card-item-num">
							{{item.cuo_num}}题
						</view>
						<view class="item-card-item-intro">
							答错	
						</view>
					</view>
					<view class="item-card-item">
						<view class="item-card-item-num">
							{{item.wei_num}}题
						</view>
						<view class="item-card-item-intro">
							未答
						</view>
					</view>
					<view class="line"></view>
					<view 
						class="fenshu"
						:style="{color:item.is_pass == 0 ? '#fa3534' : '#19be6b'}"
					>
						<view>
							{{item.score}}
						</view>
					</view>
					
				</view>
			</view>
		</view>
		<view v-else style="margin-top: 100rpx;">
			<u-empty text="暂无考试记录" />
		</view>
	</view>
</template>

<script>
	import request from "@/pagesB/common/js/request/allRequest.js"
	export default {
		data() {
			
			return {
				minHeight:'100px',
				page:{
					page:1,
					page_size:10
				},
				recordList:[],
				count:0
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.minHeight = res.windowHeight + "px"
				},
			})
			this.getTestRecord()
		},
		onPullDownRefresh() {
			setTimeout(() => uni.stopPullDownRefresh(),6000)
			this.page = {
				page:1,
				page_size:10
			}
			this.recordList = []
			this.getTestRecord()
		},
		onReachBottom() {
			if(this.count === this.recordList.length){
				this.$u.toast('暂无更多数据')
			}else{
				this.page = {
					page:this.page.page + 1,
					page_size:10
				}
				this.getTestRecord()
			}
		},
		methods: {
			//获取记录
			getTestRecord(){
				let data={}
				if(uni.getStorageSync("eduInfo").sentryPid == 5){
					data = { ...this.page}
				}else if (uni.getStorageSync("eduInfo").sentryPid == 3){
					data = { ...this.page,type:4}
				}
				uni.showLoading()
				request.getTestRecordList({
					data,
					success:(res) => {
						uni.hideLoading()
						uni.stopPullDownRefresh()
						this.count = res.count
						this.recordList = [...this.recordList,...res.list]
					},
					fail:(err) =>{
						uni.hideLoading()
					}
				})
			}
			
		}
	}
</script>

<style lang="less" scoped>
	.fenshu{
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 42rpx;
		font-family: DINPro, DINPro-Medium;
		font-weight: 500;
	}
	.line{
		height: 80rpx;
		border-left:1rpx solid #dbdbdb;
	}
	.item-card-item-intro{
		text-align: center;
		font-size: 20rpx;
		font-family: PingFangSC, PingFangSC-Regular;
		font-weight: 400;
		color: #7f7f7f;
		line-height: 28rpx;
	}
	.item-card-item-num{
		font-size: 28rpx;
		font-family: PingFangSC, PingFangSC-Medium;
		font-weight: 500;
		color: #333333;
		line-height: 40rpx;
		margin-bottom: 12rpx;
		text-align: center;
	}
	.item-card{
		box-sizing: border-box;
		padding: 24rpx 0rpx;
		background: #f6f6f6;
		border-radius: 18rpx;
		display: flex;
		justify-content: space-evenly;
		.item-card-item{
			display: flex;
			flex-direction: column;
		}
	}
	.long-time{
		font-size: 26rpx;
		font-family: PingFangSC, PingFangSC-Regular;
		font-weight: 400;
		color: #7f7f7f;
		line-height: 36rpx;
		margin: 16rpx 0 22rpx 0;
	}
	.item-title-time{
		font-size: 30rpx;
		font-family: PingFangSC, PingFangSC-Medium;
		font-weight: 500;
		color: rgba(0,0,0,0.85);
		line-height: 42rpx;
	}
	.item-title{
		display: flex;
		justify-content: space-between;
	}
	.item{
		background-color: #fff;
		border-radius: 18rpx;
		box-sizing: border-box;
		padding: 32rpx;
		margin-bottom: 20rpx;
	}
	.box{
		box-sizing: border-box;
		padding: 24rpx 24rpx;
		background-color: #f7f7f7;
	}
</style>
